﻿namespace OrderSystem.Core.Domain
{
    public class OrderItem : BaseEntity
    {
        public virtual Order Order { get; set; }
        public virtual Product Product { get; set; }
        public virtual int Quantity { get; set; }

        public override string ToString()
        {
            return string.Format("Id = {0} Product- #{1}# Amount = {2}", Id, Product, Quantity);
        }

        public override int GetHashCode()
        {
            return string.Format("{0}{1}{2}{3}{4}", GetType().Name, Id, Order.Id, Product.Id, Quantity).GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var compareOrderItem = obj as OrderItem;

            if (compareOrderItem == null) return false;

            if (compareOrderItem.GetHashCode() != GetHashCode()) return false;

            return true;
        }
    }
}
